home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Scripting_Resources / Samples / Automation_Scripts / Create Objects.js < prev    next >
Encoding:
Text File  |  2002-05-13  |  6.0 KB  |  150 lines

  1. //////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED 
  4. // Copyright 2002 Adobe Systems Incorporated 
  5. // All Rights Reserved 
  6. //
  7. // NOTICE:  Adobe permits you to use, modify, and 
  8. // distribute this file in accordance with the terms
  9. // of the Adobe license agreement accompanying it.  
  10. // If you have received this file from a source 
  11. // other than Adobe, then your use, modification,
  12. // or distribution of it requires the prior 
  13. // written permission of Adobe. 
  14. //
  15. //////////////////////////////////////////////////
  16.  
  17. //////////////////////////////////////////////////
  18. // 
  19. // Create Objects.js
  20. //
  21. // DESCRIPTION
  22. //
  23. // This script opens a new composition, creates different object in 
  24. // that composition using the createobject/convertType methods. Also 
  25. // shows how to set background gradient to the composition and single 
  26. // colors to the object.
  27. //
  28. // HOW TO USE
  29. //
  30. // Select Automation > Run Automation Scripts > Create Objects.js
  31. // Note: Keep Console window open to see the description of objects as
  32. // they get created.
  33. // 
  34. //////////////////////////////////////////////////
  35.  
  36.  
  37. // Main Code [Execution of script begins here]
  38.  
  39. if(!(comp = application.currentComposition)){
  40.     // if no composition open
  41.     // opens a new composition
  42.     comp = application.newComposition();
  43.     Console.show();
  44.     Console.write("New Composition opened\n");
  45. }
  46.  
  47. createobject(comp);// Calls function createobject
  48.  
  49. // Add your own functions here
  50.  
  51. //////////////////////////////////////////////////
  52. // createobject:
  53. //
  54. // Demonstrates how user can automatically create object on the composition.
  55. // Not only that the object can be changed to desired shapes - ellipse, polygon etc.
  56. // and placed on desired location on the composition. Also shows how different 
  57. // color/colorGradient can be given to the object/background. The file is then saved
  58. // with a new filename at a desired location on your computer.
  59. //
  60. // comp: The currently open and active file/composition.
  61. //////////////////////////////////////////////////
  62.  
  63. function createobject(comp)
  64. {
  65.     // Setting the background color of the composition to a linear gradient
  66.     comp.backgroundColorGradient.type = LMGradientType.linear;
  67.         
  68.     // Setting the start colors of the linear gradient
  69.     comp.backgroundColorGradient.startColor.red = 255;
  70.     comp.backgroundColorGradient.startColor.green = 250;
  71.     comp.backgroundColorGradient.startColor.blue = 215;
  72.         
  73.     // Setting end colors of the linear gradient
  74.     comp.backgroundColorGradient.endColor.red = 135;
  75.     comp.backgroundColorGradient.endColor.green = 245;
  76.     comp.backgroundColorGradient.endColor.blue = 190;
  77.         
  78.     // Creates a rectangle by default on the Composition at coordinates (75, 75)
  79.     // and object's index is 0 i.e.it is the first object in the composition. 
  80.     var object1 = comp.createObject(LMObjectType.geometric, 75, 75, 0); 
  81.     Console.show();
  82.     Console.write("Geometric object 1 initially created is " +  object1 + "\n");
  83.     
  84.     // Setting opacity Gradient for the object of type burst and angle 90 degree
  85.     object1.layers[0].opacityGradient.type = LMGradientType.doubleBurst;
  86.     object1.layers[0].opacityGradient.angle = 90;
  87.     
  88.     // Setting only start color for the object.
  89.     // This is same as setting a single color for object without gradient.
  90.     object1.layers[0].colorGradient.startColor.red = 0;
  91.     object1.layers[0].colorGradient.startColor.green = 150;
  92.     object1.layers[0].colorGradient.startColor.blue = 165;
  93.     
  94.     // Create aniother object at (180, 180) at object index 1 in the Composition.
  95.     var object2 = comp.createObject(LMObjectType.geometric, 180, 180, 1);
  96.     Console.write("Geometric object 2 initially created is " +  object2 + "\n");
  97.     
  98.     // Convert object2 to path object
  99.     object2 = object2.convertType(LMGeometricType.path); 
  100.     Console.write("Geometric object 2 converted to: " +  object2 + "\n");
  101.     
  102.     // Change the stroke type to outline for object2
  103.     object2.stroke.type = LMStrokeType.outline;
  104.     
  105.     // Object size can be changed - to 50,50. Initially object is created with default size
  106.     // 100,100.
  107.     object2.size.x = 50;
  108.     object2.size.y = 50;
  109.     
  110.     // Note: Path object have paths (at least one).
  111.     // Paths have knots (at least one).
  112.     // When you create a path the coordinates you are giving specify the position of the 
  113.     // first knot on the path.  To make connected dots you must add additional knots to 
  114.     // the same path.
  115.     // All knots on a same path are relative to the anchor point of the object.
  116.     
  117.     var thePath = object2.addPath(50, 0, 1) 
  118.     // Creates a path and places it's first knot at (50, 0) relative to the anchor 
  119.     // point of the object.
  120.         
  121.     // Add knots to the path at different positions, relative to anchor point of the object.
  122.     thePath.addKnot(0, 50, 1); // Index of the knot at (0, 50) in the array of knots is 1.
  123.     thePath.addKnot(-50, 0, 2); // Index of the knot at (-50, 0) in the array of knots is 2.
  124.     thePath.addKnot(0, -50, 3); // Index of the knot at (0, -50) in the array of knots is 3.
  125.     thePath.closed = true; // Closing the path connects the first and last knot.
  126.     
  127.     // You close a path when you wan to connect two points which are already knots on the path.
  128.     
  129.     // Create aniother object at (275, 275) and object index 2
  130.     var object3 = comp.createObject(LMObjectType.geometric, 275, 275, 2);// Create an object
  131.     Console.write("Geometric object 3 initially created is " +  object3 + "\n");
  132.     
  133.     // Converts object3 to polygon
  134.     object3 = object3.convertType(LMGeometricType.polygon); 
  135.     
  136.     // Number of sides of the polygon object can be set using sides.
  137.     object3.sides = 6;
  138.     Console.write("Geometric object 3 converted to: " +  object3 + "\n");
  139.     
  140.     // Saves the composition file under the default/root directory with the given name
  141.     // The second boolean arguement checks whether a file by that name already
  142.     // exists and if false does not overwrite it else overwrites.
  143.     
  144.     // The file path notation is the URI notation. Two consecutive slashes means the 
  145.     // default volume. On a Macintosh it is the volume name and on Windows it is the 
  146.     // drive name.
  147.     comp.saveComposition("//comp.liv", false);
  148.     
  149.     return; 
  150. }